package com.nuoniu.sibanyun.controller.cms;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.cms.CmsInfo;
import com.nuoniu.sibanyun.service.cms.ICmsInfoService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 网站基本设置 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/crm/info")
@Api(tags = "网站基本设置")
public class CmsInfoController extends BaseController {

    @Autowired
    private ICmsInfoService infoService;

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody CmsInfo cmsInfo) {
        infoService.saveInfo(cmsInfo);
        return HttpResult.ok();
    }

    @ApiOperation("获取基本信息")
    @GetMapping("getInfo")
    public HttpResult getInfo() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("company_id", UserThreadLocal.get().getCompanyId());
        wrapper.last("LIMIT 1");
        return HttpResult.ok(infoService.getOne(wrapper));
    }

    @ApiOperation("根据公司code获取网站信息")
    @GetMapping("{code}")
    public HttpResult getCmsInfo(@PathVariable("code") String code) {
        return HttpResult.ok(infoService.getInfoByCode(code));
    }
}
